package com.bosssoft.boss_exam_db.service.busines.impl;

import com.bosssoft.boss_exam_db.entity.Company;
import com.bosssoft.boss_exam_db.entity.Job;
import com.bosssoft.boss_exam_db.mapper.JobMapper;
import com.bosssoft.boss_exam_db.service.base.impl.BaseServiceImpl;
import com.bosssoft.boss_exam_db.service.busines.JobService;
import com.bosssoft.boss_exam_db.util.MySqlUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
@Slf4j
public class JobServiceImpl extends BaseServiceImpl<Job> implements JobService {

    //注入JobMapper
    @Autowired
    private JobMapper jobMapper;

    /***
     * @Author lys(cherish)
     * @Phone 17720799636
     * @Date  2019/4/8
     * @Description 根据条件查询岗位信息
     * @Param [company, name, page, limit, sort, order] 公司、岗位名称、分页信息
     * @Return com.github.pagehelper.PageInfo<com.bosssoft.boss_exam_db.entity.Job>
     * @Exception
     * @since JDK 1.8
     **/
    @Override
    public PageInfo<Job> queryByCondition(Company company, String name, Integer page, Integer limit, String sort, String order) {
        Example example = new Example(Job.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("companyId", company.getId());
        if (!StringUtils.isEmpty(name)) {
            criteria.andLike("name", MySqlUtil.cloumLike(name));
        }
        criteria.andEqualTo("deleted",false);
        PageInfo<Job> groupPageInfo = PageHelper.startPage(page, limit).setOrderBy(sort + " " + order).doSelectPageInfo(() ->
                this.jobMapper.selectByExample(example)
        );
        return groupPageInfo;
    }

    /***
     * @Author lys(cherish)
     * @Phone 17720799636
     * @Date  2019/4/8
     * @Description  根据公司ID查询公司
     * @Param [id] 公司ID
     * @Return java.util.List<com.bosssoft.boss_exam_db.entity.Job>
     * @Exception
     * @since JDK 1.8
     **/
    @Override
    public List<Job> queryByCompany(String id) {
        Example example = new Example(Job.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("companyId",id).andEqualTo("deleted",false);
        return  jobMapper.selectByExample(example);
    }
}
